package cn.echoedu.command;

import java.util.ArrayList;
import java.util.List;

import cn.echoedu.command.base.Command;
import cn.echoedu.command.base.ExecuteParam;
import cn.echoedu.command.base.FailureParam;
import cn.echoedu.command.base.SuccessParam;
import cn.echoedu.constants.Code;
import cn.echoedu.entity.ClassNotify;
import cn.echoedu.util.DateUtil;

import com.google.gson.Gson;

public class QueryClassNotifyList extends BaseCommand {

	public void executeSuccess(SuccessParam successparam) {
		// TODO Auto-generated method stub
		ClassNotifyListSuccess notifylistsuccess = new ClassNotifyListSuccess();
		notifylistsuccess.setCode(Code.CLASS_NOTIFY_LIST);
		notifylistsuccess.setMsg("Class Notify List Success");
		List<ClassNotify> classnotify = (List<ClassNotify>)successparam.getParam();
        List<ClassNotifyListEntity> list = new ArrayList<ClassNotifyListEntity>();
        for(int i=0,len=classnotify.size();i<len;i++){
        	ClassNotifyListEntity notifylistentity = new ClassNotifyListEntity();
        	notifylistentity.setClassnotifyid(classnotify.get(i).getClassnotify());
        	notifylistentity.setTheme(classnotify.get(i).getTitle());
        	notifylistentity.setTime(DateUtil.dateToString(classnotify.get(i).getPublishtime()));
            notifylistentity.setHitcount(classnotify.get(i).getHitcount());
        	list.add(notifylistentity);
        }
        notifylistsuccess.setList(list);
        String result = new Gson().toJson(notifylistsuccess);
        send(result,successparam.getResponse());
	}

	public void executeFailure(FailureParam failureparam) {
		// TODO Auto-generated method stub

	}

	public void execute(ExecuteParam executeparam) {
		// TODO Auto-generated method stub

	}
	class  ClassNotifyListSuccess{
		private int code;
		private String msg;
		private List<ClassNotifyListEntity> list;
		public final int getCode() {
			return code;
		}
		public final void setCode(int code) {
			this.code = code;
		}
		public final String getMsg() {
			return msg;
		}
		public final void setMsg(String msg) {
			this.msg = msg;
		}
		public final List<ClassNotifyListEntity> getList() {
			return list;
		}
		public final void setList(List<ClassNotifyListEntity> list) {
			this.list = list;
		}
        
	}
	class ClassNotifyListEntity{
		private int classnotifyid;
		private String theme;
		private String time;
		private int hitcount;
		public final int getClassnotifyid() {
			return classnotifyid;
		}
		public final void setClassnotifyid(int classnotifyid) {
			this.classnotifyid = classnotifyid;
		}
		public final String getTheme() {
			return theme;
		}
		public final void setTheme(String theme) {
			this.theme = theme;
		}
		public final String getTime() {
			return time;
		}
		public final void setTime(String time) {
			this.time = time;
		}
		public final int getHitcount() {
			return hitcount;
		}
		public final void setHitcount(int hitcount) {
			this.hitcount = hitcount;
		}
		

	}

}
